<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        .cls {
            background-color: black;
        }
    </style>
</head>

<body class="" id='body'>
    <input type="button" value="开关" id="btn">
    <ul>
        <li>网页开关灯效果实现</li>
        <li>点击按钮修改p标签内容</li>
        <li>鹦鹉学舌</li>
    </ul>
    <script type="text/javascript">
        var btn = document.getElementById('btn');

        btn.onclick = function() {
            //var body = document.getElementById('body');
            var body = document.body;
            // console.log(body);
            console.log(body.className == '');
            if (body.className == '') {
                body.className = 'cls';
            } else {
                body.className = '';
            }
        }
    </script>
</body>

</html>